#!/usr/bin/perl

$WORKDIR= $ARGV[0];
$LEGODIR= $ARGV[1];

if (($LEGODIR ne "/") && ($LEGODIR ne "//") && ($LEGODIR ne "//")) {
   	print `sudo chown -R root:admin "$LEGODIR/LEGO MINDSTORMS NXT/engine"`;
   	print `sudo chown -R root:admin "$LEGODIR/LEGO MINDSTORMS NXT/MINDSTORMS NXT.app"`;
	print `sudo chmod -R 777 "$LEGODIR/LEGO MINDSTORMS NXT/engine"`;
	print `sudo chmod -R 775 "$LEGODIR/LEGO MINDSTORMS NXT/MINDSTORMS NXT.app"`;
}	

#@filesToCheck = (
#  "/Library/Internet Plug-Ins/Flash Player.plugin",
#  "/Library/Internet Plug-Ins/flashplayer.xpt"
#  );
#$exists=1;
#
#while($exists && ($itemToCheck=pop(@filesToCheck))) {
#  $exists=-e"$itemToCheck";
#  }
#
#if($exists) {
#	`echo "Flash components already installed."`;
#  } else {
#  	# Launch the Flash installer
#	`open "$WORKDIR/Contents/Resources/Install Flash Player 9 UB"`;
#  }

print &WriteGlobalvarsJS("$LEGODIR/LEGO MINDSTORMS NXT");

sub WriteGlobalvarsJS {
	local $jsPath = shift;
	local $jsFile;

#	print $jsPath."\n";

	$jsFile = $jsPath."/engine/EditorVIs/Academy Content/globalvars.js";
	$jsPath = $jsPath."/engine/EditorVIs/Academy%20Content/\";";
	$spot = index($jsPath,"\ "); 
	while ($spot != -1) 
	{
		substr($jsPath, $spot, 1) = "%20";
		$spot = index($jsPath,"\ "); 
	}
	$jsPath = "siteRoot = \"file://localhost".$jsPath;
	binmode STDOUT,":utf8";
	print `echo '$jsPath' > \"$jsFile\"`;
}
